#ifndef ITEMMODEL_H
#define ITEMMODEL_H

#include <QAbstractListModel>
#include "baza/artikl.h"
#include "itemitem.h"

class ItemModel: public QAbstractListModel
{
   Q_OBJECT

   Q_PROPERTY(int count READ count NOTIFY countChanged)

public:
   enum ListItemRoles  {
       RoleItemName = Qt::DisplayRole,
       RoleItemId = Qt::UserRole,
       RoleGroupId = Qt::UserRole+1,
       RoleGroupName = Qt::UserRole+2,
       RoleIsAGroup = Qt::UserRole+3,
       RoleIndex = Qt::UserRole+4,
       RoleGroupNumber = Qt::UserRole+5
   };

   ItemModel(QObject *parent = 0);

   void addItem(const Artikl &item, int index, bool isAGroup, int groupCount);
   void clear();

   int rowCount(const QModelIndex & parent = QModelIndex()) const;
   int count();

   Q_INVOKABLE ItemItem* get(int index);
   QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;

   /*Qt::ItemFlags flags(const QModelIndex &index) const;
   QVariant headerData(int section, Qt::Orientation orientation,
                                    int role) const;*/
QModelIndex indexFromItem(const ItemItem *item) const;

private slots:
   void handleItemChange();

signals:
   void countChanged(int newCount);

private:
   QList<ItemItem*> m_Items;
};


#endif // ITEMMODEL_H
